package com.bb.flow.service.imp.node;

import com.bb.flow.api.FlowNode;
import com.bb.flow.api.NotifyExecuteResult;
import com.bb.flow.api.entries.FlowContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public abstract class FlowNodeBase implements FlowNode {

    public Logger logger = LoggerFactory.getLogger(this.getClass());

    public int waitTime = 1;

    private NotifyExecuteResult flowNodeCallBack;
    private FlowContext flowNodeData;

    @Override
    public boolean initNode() {
        logger.info("{}开始初始化", this.toString());
        return true;
    }

    @Override
    public NotifyExecuteResult getExecuteOverNotify() {
        return flowNodeCallBack;
    }

    @Override
    public void setExecuteOverNotify(NotifyExecuteResult flowNodeCallBack) {
        this.flowNodeCallBack = flowNodeCallBack;
    }

    @Override
    public FlowContext getFlowNodeData() {
        return flowNodeData;
    }

    @Override
    public void setFlowNodeData(FlowContext flowNodeData) {
        this.flowNodeData = flowNodeData;
        //System.out.println("流程上下文数据:" + flowNodeData);
    }

    public void notifyDriver() {
        notifyDriver(true);
    }

    public void notifyDriver(boolean unregister) {
        if (this.getExecuteOverNotify() != null) {
            this.getExecuteOverNotify().notifyResult(unregister);
        } else {
            System.out.println(this.toString() + ":flowNodeCallBack is null ");
        }
    }
}
